<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>开标</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" placeholder="请输入" readonly autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>开标信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">开标结果</label>
                        <div class="layui-input-block">
                            <select id="kaiguo" name="kaiguo" lay-filter="kaiguo" >
                                <option value="">请选择</option>
                                <option value="中标">中标</option>
                                <option value="未中标">未中标</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide wininfo">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>中标单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=winunit&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="winunit"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=winunit&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="winunit_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide wininfo">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>中标金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="winfee" id="winfee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">中标日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="windt" id="windt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">开标说明</label>
                        <div class="layui-input-block">
                            <input type="text" name="kaishuo" id="kaishuo" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>

        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;
    $("#commentForm").validate({
        rules: {
            winfee: {required: true},
        },
        messages:{
            winfee: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_kai,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $("#name").val(data.name);
                $("#kaiguo").val(data.kaiguo);
                $("#winfee").val(data.winfee);
                $("#windt").val(data.windt);
                $("#kaishuo").val(data.kaishuo);

                if(data.winunit_info.length > 0){
                    tan_tags_init('#winunit', data.winunit_info);
                }

                if(data.kaiguo == '中标'){
                    $(".wininfo").removeClass('layui-hide');
                }else{
                    $(".wininfo").addClass('layui-hide');
                }

                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(kaiguo)', function(data){
            if(data.value == '中标'){
                $(".wininfo").removeClass('layui-hide');
            }else{
                $(".wininfo").addClass('layui-hide');
            }
        });

        form.on('submit(add)', function(data){

            data.field.winunit = tan_tags_getvalue("#winunit", 'dept');

            var validRes = $("#commentForm").valid();

            if(data.field.kaiguo == '中标'){
                if(!data.field.winunit){
                    $("#winunit").parents('.tanxian').addClass('tanerror');
                    $('#winunit_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#winunit").parents('.tanxian').removeClass('tanerror');
                    $('#winunit_tanerror').text('');
                }
            }


            if(!validRes){return false;}

            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_engin_kai, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
